﻿using System.IO;
using Lucid.ESA.ClientDataSystem.Application.Contracts;
using Lucid.ESA.ClientDataSystem.Application.DataTransferObjects;
using Lucid.ESA.ClientDataSystem.Application.Responses;
using Lucid.ESA.ClientDataSystem.Data.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StructureMap;

namespace Lucid.ESA.ClientDataSystem.IntegrationTests
{
    [TestClass]
    public class ClientServiceTest
    {
        [TestInitialize()]
        public void MyTestInitialize()
        {
            //Get a fresh copy of the database.
            if (File.Exists("ClientDataSystem.sdf"))
                File.Delete("ClientDataSystem.sdf");

            File.Copy("InitialClientDataSystem.sdf", "ClientDataSystem.sdf");
        }

        [TestCleanup()]
        public void MyTestCleanup()
        {
            //Ensure session is closed after each test.
            SessionProvider.CloseSession();
        }

        [TestMethod]
        public void CanGetClientById()
        {
            IClientService clientService = ObjectFactory.GetInstance<IClientService>();
            Response response = clientService.GetClientById(1L);
            Assert.AreEqual(ResponseStatus.Success, response.Status);
            ClientDto clientDto = (response as GetResponse<ClientDto>).Value;
            Assert.AreEqual(1, clientDto.Id.Value);
            Assert.AreEqual("Indigo Industries", clientDto.Name);
        }
    }
}
